<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="./tools/axios.js"></script>
</head>

<body>

    <button>发起请求</button>
    <script>

        const btn = document.querySelector('button');

        // 注册事件，发起请求
        btn.addEventListener('click', async function () {
            // 使用简易版的axios
            // axios({
            //     url: 'http://localhost:5100/users',
            //     params: {
            //         id: 56
            //     }
            // })
            //     .then(data => {
            //         console.log(data);
            //     })

            // 结合 async 和 await 
            try {
                const res = await axios({
                    url: 'http://localhost:5100/users1',
                    params: { id: 32 }
                })

                console.log(res);
            } catch (e) {
                console.log(e);
            }

            // console.log(res);
        })

    </script>
</body>

</html>